﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Nirvana
{
    /// <summary>
    /// UI优化检测脚本，用于检测开启了Raycast Target功能的UI，为了优化，一般不需要的ui最好都关闭
    /// </summary>
    public class UIRaycastDebug : MonoBehaviour
    {
        private Vector3[] wroldCorners = new Vector3[4];
        private List<Graphic> _grapList = new List<Graphic>();

        void OnDrawGizmos()
        {
            Gizmos.color = Color.blue;
            GetComponentsInChildren<Graphic>(this._grapList);
            foreach(var p in this._grapList)
            {
                if (p.raycastTarget)
                {
                    p.rectTransform.GetWorldCorners(this.wroldCorners);
                    for(int i = 0; i < 4; i++)
                    {
                        Gizmos.DrawLine(this.wroldCorners[i], this.wroldCorners[(i + 1) % 4]);
                    }

                }
            }
        }
    
    }
}

